/**
 *
 */
package com.fzy.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StopWatch;

/**
 * @author 冯赵杨
 * @desc 统计工具类
 * @date 2016年12月7日
 */
public class StopWatchUtil {

    private StopWatchUtil() {
    }

    private static final Logger logger = LoggerFactory.getLogger(StopWatchUtil.class);

    public static StopWatch start() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        return stopWatch;
    }

    public static void stop(StopWatch stopWatch) {
        stopWatch.stop();
    }

    public static void getTotalTime(StopWatch stopWatch) {
        logger.info("执行时间 :{}分=={}秒=={}毫秒", stopWatch.getTotalTimeSeconds() / 60, stopWatch.getTotalTimeSeconds(),
                stopWatch.getTotalTimeMillis());
    }

    public static void main(String[] args) {
        StopWatch watch = StopWatchUtil.start();

        int count = 0;
        for (int i = 0; i < 1000000; i++) {
            i++;
            count = i;

            System.out.print(count);

        }

        StopWatchUtil.stop(watch);

        StopWatchUtil.getTotalTime(watch);

        StopWatch watch2 = StopWatchUtil.start();

        int count2 = 0;
        for (int i = 0; i < 1000000; i++) {
            i++;
            count2 = i;

            System.out.print(count2);
        }

        StopWatchUtil.stop(watch2);

        StopWatchUtil.getTotalTime(watch2);
    }
}
